package com.ruoyi.ftrl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ftrl.domain.AreasInfo;
import com.ruoyi.ftrl.service.IAreasInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 片区信息Controller
 * 
 * @author 邸航
 * @date 2024-08-05
 */
@RestController
@RequestMapping("/ftrl/areas")
public class AreasInfoController extends BaseController
{
    @Autowired
    private IAreasInfoService areasInfoService;

    /**
     * 供热质量查询片区列表以及各个片区下的子级热力站的平均温度
     */
    @GetMapping("/childs")
    public TableDataInfo allLists(String name){
        List<AreasInfo>list=areasInfoService.selectAreasInfoListAlls(name);
        return getDataTable(list);
    }

    /**
     * 查询片区列表以及各个片区下的子级热力站
     */
    @GetMapping("/child")
    public TableDataInfo allList(String name){
        List<AreasInfo>list=areasInfoService.selectAreasInfoListAll(name);
        return getDataTable(list);
    }

    /**
     * 查询片区信息列表
     */
    @PreAuthorize("@ss.hasPermi('ftrl:areas:list')")
    @GetMapping("/list")
    public TableDataInfo list(AreasInfo areasInfo)
    {
        startPage();
        List<AreasInfo> list = areasInfoService.selectAreasInfoList(areasInfo);
        return getDataTable(list);
    }

    /**
     * 导出片区信息列表
     */
    @PreAuthorize("@ss.hasPermi('ftrl:areas:export')")
    @Log(title = "片区信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AreasInfo areasInfo)
    {
        List<AreasInfo> list = areasInfoService.selectAreasInfoList(areasInfo);
        ExcelUtil<AreasInfo> util = new ExcelUtil<AreasInfo>(AreasInfo.class);
        util.exportExcel(response, list, "片区信息数据");
    }

    /**
     * 获取片区信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:areas:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(areasInfoService.selectAreasInfoById(id));
    }

    /**
     * 新增片区信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:areas:add')")
    @Log(title = "片区信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AreasInfo areasInfo)
    {
        return toAjax(areasInfoService.insertAreasInfo(areasInfo));
    }

    /**
     * 修改片区信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:areas:edit')")
    @Log(title = "片区信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AreasInfo areasInfo)
    {
        return toAjax(areasInfoService.updateAreasInfo(areasInfo));
    }

    /**
     * 删除片区信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:areas:remove')")
    @Log(title = "片区信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(areasInfoService.deleteAreasInfoByIds(ids));
    }
}
